package com.hong.serviceuser.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hong.commonutil.result.Result;
import com.hong.model.model.user.UserInfo;
import com.hong.model.vo.acl.UserQueryVo;
import com.hong.model.vo.user.UserInfoQueryVo;
import com.hong.serviceuser.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Api("后台管理系统对用户的操作")
@RestController
@RequestMapping("/admin/user/")
public class UserController {
    @Autowired
    private UserInfoService userInfoService;
    @ApiOperation("查询用户列表(条件查询带分页)")
    @GetMapping("{page}/{limit}")
    public Result userList(@PathVariable int page, @PathVariable int limit, UserInfoQueryVo userInfoQueryVo){
        Page<UserInfo> pageParm = new Page<>(page, limit);
        IPage<UserInfo> pageModel =  userInfoService.selectPage(pageParm, userInfoQueryVo);
        return Result.ok(pageModel);
    }
    @ApiOperation("用户锁定和解锁")
    @GetMapping("lock/{userId}/{status}")
    public Result userList(@PathVariable Long userId, @PathVariable Integer status){
        userInfoService.lock(userId,status);
        return Result.ok();
    }
    @ApiOperation("用户详情")
    @GetMapping("show/{userId}")
    public Result userList(@PathVariable Long userId){
        Map<String,Object> userInfo = userInfoService.show(userId);
        return Result.ok(userInfo);
    }
    @ApiOperation("用户审批")
    @GetMapping("approve/{userId}/{authStatus}")
    public Result approve(@PathVariable Long userId, @PathVariable Integer authStatus){
        userInfoService.approval(userId,authStatus);
        return Result.ok();
    }
    @ApiOperation("根据认证用户姓名模糊查询用户列表")
    @GetMapping("findUserListByUserName/{username}")
    public List<UserInfo> findUserListByUserName(@PathVariable String username){
        List<UserInfo> userInfoList =  userInfoService.findUserListByUserName(username);
        return userInfoList;
    }
    @ApiOperation("根据用户id查询用户认证姓名")
    @GetMapping("findUserById/{userId}")
    public UserInfo findUserById(@PathVariable Long userId){
        UserInfo userInfo = userInfoService.getById(userId);
        return userInfo;
    }
}
